package com.zjj.day0425.date;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;


public class News {
    String title;
    String content;
    LocalDateTime time;

    public News(String title, String content, LocalDateTime time) {
        this.title = title;
        this.content = content;
        this.time = time;
    }

    @Override
    public String toString() {
        return "标题: " + title + ", 内容: " + content + ", 时间: " + time;
    }

    public static void main(String[] args) {
        List<News> newsList = new ArrayList<>();

        newsList.add(new News("新闻1", "内容1", LocalDateTime.of(2025, 1, 1, 0, 0)));
        newsList.add(new News("新闻2", "内容2", LocalDateTime.of(2024, 1, 1, 0, 0)));
        newsList.add(new News("新闻3", "内容3", LocalDateTime.of(2023, 1, 1, 0, 0)));
        newsList.add(new News("新闻4", "内容4", LocalDateTime.of(2022, 1, 1, 0, 0)));
        newsList.add(new News("新闻5", "内容5", LocalDateTime.of(2021, 1, 1, 0, 0)));
        newsList.add(new News("新闻6", "内容6", LocalDateTime.of(2020, 1, 1, 0, 0)));
        newsList.add(new News("新闻7", "内容7", LocalDateTime.of(2019, 1, 1, 0, 0)));
        newsList.add(new News("新闻8", "内容8", LocalDateTime.of(2018, 1, 1, 0, 0)));
        newsList.add(new News("新闻9", "内容9", LocalDateTime.of(2017, 1, 1, 0, 0)));
        newsList.add(new News("新闻10", "内容10", LocalDateTime.of(2016, 1, 1, 0, 0)));

        newsList.sort((n1, n2) -> n2.time.compareTo(n1.time));
        System.out.println("按时间降序排列的新闻列表:");

        for (News news : newsList) {
            System.out.println(news);
        }
    }
}